#include "stdafx.h"
#include "service\storage\file\ExportFileService.h"
#include "model\Match.h"
#include <algorithm>

ExportFileService::ExportFileService() {

}

ExportFileService::ExportFileService(const std::string fname,
                                     const std::ios::openmode mode)
  : BaseFileService(fname, mode) {

}

ExportFileService::ExportFileService(std::fstream& file) : BaseFileService(file) {

}

ExportFileService::~ExportFileService() {

}


ExportFileService& ExportFileService::ExportMatchSchedule(const std::vector<Match> matches) {
  file() << "\tDate\tHome\t\t\t\tAway\n\n";
  for (unsigned i = 0; i < matches.size(); i++) {
    file() << '\t' << matches[i].date().substr(6,2) << '/'
           <<  matches[i].date().substr(4,2)
           << '\t' << std::left << std::setw(24) 
           << matches[i].home_team()  << 'v' 
           << '\t' << matches[i].guest_team() << "\n";       
  }
  return *this;
}


ExportFileService& ExportFileService::ExportResult(const std::vector<Match> matches) {
  file() << "\tDate\tHome\t\t\t\tAway\n\n";
  for (unsigned i = 0; i < matches.size(); i++) {
    file() << '\t'  << matches[i].date().substr(6,2) << '/'
           <<  matches[i].date().substr(4,2)
           << "\t" << std::left << std::setw(24) 
           << matches[i].home_team(); 

    if(matches[i].HasResult()) {
      file() << matches[i].home_score() << '-' << matches[i].guest_score();
    } else {
      file() << 'v';
    }

    file() << '\t' << matches[i].guest_team() << "\n";  
  }
  return *this;
}


ExportFileService& ExportFileService::ExportTable(const Division& division) {
  return *this;
}